from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    浏览器 = p.chromium.launch(headless=False,args=['--start-maximized'])
    上下文 = 浏览器.new_context()
    page = 浏览器.new_page()

    # 监听方法
    def on_load():
        print("页面加载完成!")
        print(f"当前页面URL: {page.url}")
        print(f"当前页面标题: {page.title()}")

    # 监听页面加载完成事件
    page.on('load', on_load)

    # 打开仓储系统
    page.goto("http://172.28.1.3:2460/")
    # 输入账号和密码
    page.get_by_placeholder("您的账号").type("kuanglei", delay=30)
    page.get_by_placeholder("请输入您的密码").fill("123456")
    # 点击登录
    page.get_by_role("button").click()
    # 进入入库管理页面
    page.get_by_text("入库管理").click()
    page.get_by_role("link", name="入库单").click()
    page.get_by_role("button", name="新增入库").click()
    page.get_by_placeholder("请选择客户类型").click()
    page.get_by_text("仓储物流").click()
    page.get_by_placeholder("请选择公司名称").click()
    page.get_by_text("星月科技(小星,13200000009)").click()
    page.get_by_placeholder("请选择仓库").click()
    page.locator("li").filter(has_text="南城仓").click()
    page.get_by_role("button", name="添加货物").click()
    # 选择品类、品名、厂家、牌号
    page.locator("label").filter(has_text="通用塑料").click()
    page.locator("span").filter(has=page.get_by_placeholder("请选择品类")).click()
    page.locator("li").filter(has_text="ABS").click()
    page.locator("span").filter(has=page.get_by_placeholder("请选择厂家")).click()
    page.get_by_text("北京首塑").click()
    page.locator("span").filter(has=page.get_by_placeholder("请选择牌号")).click()
    page.get_by_text("A310", exact=True).click()

    # 入库货物
    page.get_by_placeholder("请选择库区").click()
    page.get_by_text("库区1").click()
    page.get_by_placeholder("请选择库位").click()
    page.get_by_text("库位1").click()
    page.get_by_placeholder("请选择货物性质").click()
    page.locator("li").filter(has_text="代采").click()
    page.get_by_placeholder("请选择存储计价类型").click()
    page.get_by_text("弹性体").click()
    page.get_by_placeholder("请输入包装规格(kg/包)").click()
    page.get_by_placeholder("请输入包装规格(kg/包)").fill("100")
    page.get_by_placeholder("请输入重量(吨)").click()
    page.get_by_placeholder("请输入重量(吨)").fill("30")
    page.get_by_placeholder("请输入数量（个/包/桶/板）").click()
    page.get_by_placeholder("请选择原料状态").click()
    page.locator("li").filter(has_text="固体").click()
    page.get_by_placeholder("请输入批次号").click()
    page.get_by_placeholder("请输入批次号").fill("007")
    page.locator("form").filter(has_text="品类 通用塑料工程塑料化工用料改性/再生塑料品类 ABS").get_by_role(
        "button").click()

    # 编辑送货信息
    page.get_by_placeholder("请输入入库车辆牌号").click()
    page.get_by_placeholder("请输入入库车辆牌号").fill("粤B001")
    page.get_by_placeholder("请选择送货时间").click()
    page.get_by_text("今天").click()
    page.get_by_placeholder("请输入司机姓名").click()
    page.get_by_placeholder("请输入司机姓名").fill("张三丰")
    page.get_by_placeholder("请输入司机手机号").click()
    page.get_by_placeholder("请输入司机手机号").fill("13200000001")
    page.get_by_placeholder("请输入司机身份证号").click()
    page.get_by_placeholder("请输入司机身份证号").fill("42900100000006")

    # 是否加班单选按钮,选择"是"
    page.locator(".arco-radio-icon").first.click()
    # 是否质检,选择"是"
    page.locator("label").filter(has_text="是").nth(3).click()
    # 提交
    page.get_by_role("button", name="提交").click()
    page.wait_for_timeout(5000)

    # 新开一个页面
    page1 = 浏览器.new_page()
    page1.goto("https://www.baidu.com/")
    page1.locator("#kw").fill("playwright page.on()")
    page1.get_by_role("button", name="百度一下").click()
    page1.wait_for_timeout(5000)

    # 关闭浏览器
    浏览器.close()




